const express = require('express');
const path = require('path');
const fs = require('fs');
const time = require('time-stamp');
const app = express();
app.listen(3000, () => {
  console.log('服务器已开启')
});
const router = express.Router();
//读取文件
let data = JSON.parse(fs.readFileSync(path.join(__dirname, 'persons.json')))
app.use(express.urlencoded({extended: false}))


app.use(express.static(path.join(__dirname, '../view')))
//渲染login
app.get('/login', (req, res) => {
  res.sendFile(path.join(__dirname, '../view/login.html'))
})
//登录
app.post('/login', (req, res) => {
  let {
    username,
    password
  } = req.body
  let a = data.find(function (item) {
    return  item.username == username && item.password == password
  })
  console.log(a);
  if (a) {
    res.send('登录成功');
  } else {
    res.send('用户名或密码错误');
  }
})
module.exports = app;